package com.by.auto;

import com.by.interceptor.TokenWebConfig;
import com.by.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 江俊俊
 * @version 1.0
 * @description
 * @date 2025/2/12 19:41
 * @since JDK1.8
 */
@AutoConfiguration(after = TokenAutoConfigure.class)
@EnableConfigurationProperties(TokenInterceptionProperties.class)
@ConditionalOnClass(value = {HandlerInterceptor.class,WebMvcConfigurer.class})
@ConditionalOnProperty(prefix = "token.interceptor",value = "enabled",matchIfMissing = true)
public class TokenInterceptionAutoConfigure {
    /**
     *  向spring容器中注入 webmvc配置类
     * @param properties
     * @param tokenTemplate
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer(TokenInterceptionProperties properties, TokenTemplate tokenTemplate) {
        TokenWebConfig webConfig = new TokenWebConfig(properties,tokenTemplate);
        return webConfig;
    }
}
